<?php


namespace app\api\controller;


use app\BaseController;
use app\common\facade\auth\Auth;
use app\model\Agent;
use app\model\AgentServiceConfig;

class ProfitShare extends BaseController
{
    protected $middleware = [
        \app\middleware\ApiChannel::class,
        \app\middleware\ApiUserAuthV2::class => ['except' => ['phoneInfo']],
    ];

    protected function initialize()
    {
        parent::initialize();
    }

    /**
     * 有美生活
     * @return \think\response\Json
     * 查询代理分润比例
     */
    public function ymshProfit()
    {
        $agent_id = Auth::agentId();
        $agent = Agent::where('id', $agent_id)->field('id, status, merchant_id')->find();
        if (!$agent) {
            return fail('查询失败，代理不存在');
        }
        if ($agent->status == Agent::STATUS_CLOSE) {
            return fail('查询失败，代理已被禁用');
        }
        $list = AgentServiceConfig::query()->where('status', AgentServiceConfig::STATUS_ACTIVE)
            ->where('agent_id', $agent_id)
            ->field('agent_id, serv_type, value')
            ->order('serv_type asc')
            ->select();
        return success('查询成功', $list);
    }
}